package com.bkgy.modularbx.theme.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bkgy.commom.model.QueryDTO;
import com.bkgy.modularbx.theme.domain.ThemeData;
import com.bkgy.modularbx.theme.dto.ThemeDataDeleteDto;
import com.bkgy.modularbx.theme.dto.ThemeDataDto;
import com.bkgy.modularbx.theme.dto.ThemeDataUpdateDto;
import com.bkgy.modularbx.theme.service.ThemeDataService;
import com.bkgy.sys.common.entity.ResultData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@Tag(name = "主题数据管理", description = "主题数据相关接口")
@RestController
@RequestMapping("/theme")
@Validated
public class ThemeDataController {

    @Resource
    private ThemeDataService themeDataService;

    @Operation(summary = "新增主题数据", description = "添加新的主题数据记录")
    @PostMapping("/add")
    public ResultData<Void> add(@Parameter(description = "主题数据信息") @RequestBody @Valid ThemeData themeData) {
        return themeDataService.addThemeData(themeData);
    }

    @Operation(summary = "分页查询主题数据", description = "根据条件分页查询主题数据信息")
    @PostMapping("/page")
    public ResultData<Page<ThemeData>> page(@Parameter(description = "查询条件和分页信息") @RequestBody @Valid QueryDTO<ThemeDataDto> queryDTO) {
        return themeDataService.pageThemeData(queryDTO);
    }

    @Operation(summary = "删除主题数据", description = "根据主题组ID和主题变量名删除主题数据记录")
    @PostMapping("/delete")
    public ResultData<Void> delete(@Parameter(description = "删除条件") @RequestBody @Valid ThemeDataDeleteDto dto) {
        return themeDataService.deleteThemeData(dto.getThemeGroupId(), dto.getThemeVariable());
    }

    @Operation(summary = "修改主题数据", description = "更新主题数据信息")
    @PostMapping("/update")
    public ResultData<Void> update(@Parameter(description = "更新的主题数据信息") @RequestBody @Valid ThemeDataUpdateDto dto) {
        ThemeData themeData = new ThemeData();
        BeanUtils.copyProperties(dto, themeData);
        return themeDataService.updateThemeData(themeData);
    }

    @Operation(summary = "查询主题数据详情", description = "根据主题组ID和主题变量名查询主题数据详细信息")
    @PostMapping("/findByUniqueIndex")
    public ResultData<ThemeData> findByUniqueIndex(@Parameter(description = "查询条件") @RequestBody @Valid ThemeDataDeleteDto dto) {
        return themeDataService.findById(dto.getThemeGroupId(), dto.getThemeVariable());
    }
}